import { Injectable } from '@angular/core';
// import { API_URL } from '../const/base.const';
import { HttpService } from './http.service';
import { API_URL } from '../const/base.const';

@Injectable({
  providedIn: 'root',
})
export class FeatureService {
  constructor(private $http: HttpService) {}

  getFeatures(searchKey?: string) {
    let url = API_URL.FEATURES;
    if (searchKey) {
      url += `?searchKey=${searchKey}`;
    }
    return this.$http.get(url);
  }

  getFeatureById(id: number) {
    return this.$http.get(`${API_URL.FEATURES}/${id}`);
  }

  //保存数据
  postFeature(data: any) {
    return this.$http.post(API_URL.FEATURES, data);
  }

  updateFeature(id: number, data: any) {
    return this.$http.patch(`${API_URL.FEATURES}/${id}`, data);
  }

  updateFeatureBatch(data: any) {
    return this.$http.post(`${API_URL.FEATURES}/updateBatch`, data);
  }

  deleteFeature(id: number) {
    return this.$http.delete(`${API_URL.FEATURES}/${id}`);
  }

  /**
   *根据FeatureId,查询下属的scenarios
   * @param featureId feature的id
   * @returns
   */
  queryScenariosByFeatureId(featureId: number) {
    return this.$http.post(`${API_URL.FEATURES}/scenario/${featureId}`, {});
  }

  /**
   *更新本feature是否拥有前置操作
   * @param id feature的id
   * @param hasPreAction 是否拥有前置操作
   * */
  updateHasPreaction(id: number, hasPreAction: boolean) {
    return this.$http.patch(`${API_URL.FEATURES}/update/preAction`, {
      id,
      hasPreAction,
    });
  }
}
